// 高级类型
//1.class
class Person {
    age: number
    name = '男'
    hobby: string

    // 构造函数  constructor
    constructor(age: number, name: string, hobby: string) {
        this.age = age
        this.name = name
        this.hobby = hobby
    }

    // 对象方法
    scaleAge(n: number) {
        this.age *= n
    }
}

let p = new Person(10, '小明', '足球');
console.log(p.age);
p.scaleAge(5);
console.log(p.age);
console.log()

// 继承
class Animal {
    age: number
    // readonly修饰符  只能用于修饰属性  可以赋初始值， 也可以在构造函数中赋值，其他地方不能修改
    readonly mao
    readonly dd = 56

    private move() {
        console.log("动物公共移动")
    }

    constructor(age: number, mao: number) {
        this.age = age;
        this.mao = mao
    }
}


class Dog extends Animal {
    name: string

    constructor(mao: number, age: number, name: string) {
        super(age, mao)
        this.name = name
    }

    move1() {
        console.log("狗狗自己移动")
    }
}

const dog = new Dog(43, 15, '晶晶')
console.log(dog.name)
console.log(dog.age)
dog.move1()
console.log()

// 实现接口
interface Singable {
    sing(): void
}

class People implements Singable {
    sing() {
        console.log("sing")
    }
}

let people = new People()
people.sing()

// readonly 在interface中使用
interface danceable {
    readonly s: number
}

let d: danceable = {
    s: 34
}
// d.s = 45 // 这句会报错，无法修改

let x: { readonly age: number } = {
    age: 32
}

// x.age= 89 // 这句也会报错 无法修改
